package com.redteam.data.beans;

import java.io.Serializable;
import java.sql.Date;
import java.text.DecimalFormat;

/**
 * A java bean for house account.
 * @author Teddy Karam
 */
public final class HouseAccount implements Serializable {

    private long accountNumber;
    private double balance;
    private Date dueDate;
    private Person person;
    private long fboID;
    private static final long serialVersionUID = 1L;

    /**
     * Full constructor of house account
     * @param accountNumber
     * @param person 
     * @param balance
     * @param dueDate
     * @param fboID
     */
    public HouseAccount(long accountNumber, Person person, double balance, Date dueDate, int fboID) {

        this.setAccountNumber(accountNumber);
        this.setPerson(person);
        this.setBalance(balance);
        this.setFboID(fboID);
        this.dueDate = dueDate;
    }

    /**
     * Default constructor
     */
    public HouseAccount() {
        this.setPerson(new Person());
    }

    /*
     * Returns the account number associated with this account
     * @return the accountNumber
     */
    public long getAccountNumber() {
        return accountNumber;
    }

    /**
     * Returns the person associated with this account
     * @return person
     */
    public Person getPerson() {
        return person;
    }

    /**
     * Set the person associated with this account
     * @param person
     */
    public void setPerson(Person person) {
        this.person = person;
    }

    /**
     * Set the account number associated with this account
     * @param accountNumber the accountNumber to set
     */
    public void setAccountNumber(Long accountNumber) {
        this.accountNumber = accountNumber;
    }

    /**
     * Returns the current balance on the account
     * @return the balance
     */
    public double getBalance() {
        return balance;
    }

    /**
     * Sets the balance on this account
     * @param balance the balance to set
     */
    public void setBalance(double balance) {
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        this.balance = Double.valueOf(twoDForm.format(balance));
    }

    /**
     * Returns the payment due date for the balance on the account
     * @return the dueDate
     */
    public Date getDueDate() {
        return dueDate;
    }

    /**
     * Sets the payment due date for the balance on the account
     * @param dueDate the dueDate to set
     */
    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    /**
     * Returns the FBO id associated with this account
     * @return fboID
     */
    public long getFboID() {
        return fboID;
    }

    /**
     * Sets the FBO id associated with this account
     * @param fboID
     */
    public void setFboID(int fboID) {
        this.fboID = fboID;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final HouseAccount other = (HouseAccount) obj;
        if (this.accountNumber != other.accountNumber) {
            return false;
        }
        if (Double.doubleToLongBits(this.balance) != Double.doubleToLongBits(other.balance)) {
            return false;
        }
        if (this.dueDate != other.dueDate && (this.dueDate == null || !this.dueDate.equals(other.dueDate))) {
            return false;
        }
        if (this.person != other.person && (this.person == null || !this.person.equals(other.person))) {
            return false;
        }
        if (this.fboID != other.fboID) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 43 * hash + (int) (this.accountNumber ^ (this.accountNumber >>> 32));
        hash = 43 * hash + (int) (Double.doubleToLongBits(this.balance) ^ (Double.doubleToLongBits(this.balance) >>> 32));
        hash = 43 * hash + (this.dueDate != null ? this.dueDate.hashCode() : 0);
        hash = 43 * hash + (this.person != null ? this.person.hashCode() : 0);
        hash = 43 * hash + (int) (this.fboID ^ (this.fboID >>> 32));
        return hash;
    }
}
